package cn.com.yx.ms.controller;

import cn.com.yx.ms.domain.mq.MessageBase;
import cn.com.yx.ms.domain.mq.upstream.U_Message4009;
import cn.com.yx.ms.service.IMqService;
import cn.yx.framework.configuration.AppConstant;
import cn.yx.framework.view.ApiResult;
import com.alibaba.fastjson.JSON;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.net.URLDecoder;

/**
 * 应用中心
 */
@RestController
@RequestMapping(value = "websocket")
@Api(value = "WebSocket指令中转", description = "用于WebSocket指令中转")
public class WebSocketController {

    private static final Logger logger = LoggerFactory.getLogger(WebSocketController.class);


    @Resource
    private IMqService iMqService;

    @PostMapping()
    public ApiResult receive(HttpServletRequest request) throws Exception {
        iMqService.receive(URLDecoder.decode(request.getParameter("message"), "UTF-8"));
        return new ApiResult(AppConstant.MSG_SUCCESS, true, "", "");
    }

    @PostMapping("{devsn}/4009")
    @ApiOperation(value = "截屏请求", notes = "截屏请求实体")
    @ApiImplicitParam(paramType = "body", name = "m4009", dataType = "Map", required = true, value = "测试实体详细信息")
    public ApiResult post4009(@PathVariable("devsn") String devsn, @RequestBody @Validated MessageBase<U_Message4009> m4009, BindingResult bindingResult) throws Exception {
        iMqService.receive4009(devsn, JSON.toJSONString(m4009));
        return new ApiResult<>(AppConstant.MSG_SUCCESS, true, "", null);
    }


}